package cn.zhaoyuening.chat_server.utils;

import cn.zhaoyuening.chat_server.container.ChannelContainer;
import cn.zhaoyuening.chat_common.msg.BaseMsg;
import io.netty.channel.Channel;

import java.util.Collection;

/**
 * Created by Buynow on 2017/6/14.
 */
public class MsgHelper {
    public static void sendToAllChannel(BaseMsg msg, ChannelContainer container) {
        Collection<Channel> channels = container.allChannel();
        for (Channel channel :
                channels) {
            if (channel.isWritable()) {
                channel.writeAndFlush(msg);
            }
        }
    }

    public static void sendToChannel(BaseMsg msg, Channel channel) {
        if (channel.isWritable()) {
            channel.writeAndFlush(msg);
        }
    }
}
